package com.example.xinli.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.xinli.dao.HuibidanganMapper;
import com.example.xinli.dao.ZhengnianlianxiMapper;
import com.example.xinli.domain.entity.Huibidangan;
import com.example.xinli.domain.entity.Zhengnianlianxi;
import com.example.xinli.domain.vo.HuibidanganSubmitVo;
import com.example.xinli.domain.vo.ResponseBean;
import com.example.xinli.domain.vo.ResponseBeanEnum;
import com.example.xinli.domain.vo.ZhengnianlianxiSubmitVo;
import com.example.xinli.service.IHuibidanganService;
import com.example.xinli.service.IZhengnianlianxiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class HuibidanganServiceImpl extends ServiceImpl<HuibidanganMapper, Huibidangan> implements IHuibidanganService {

    @Autowired
    HuibidanganMapper huibidanganMapper;

    @Override
    public ResponseBean getAllUserHuibidangan(String userId) {
        QueryWrapper<Huibidangan> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        List<Huibidangan> huibidanganList = huibidanganMapper.selectList(queryWrapper);
        return ResponseBean.success(huibidanganList);
    }

    @Override
    public ResponseBean submitHuibidangan(HuibidanganSubmitVo huibidanganSubmitVo) {
        Huibidangan huibidangan = new Huibidangan();
        huibidangan.setUserId(huibidanganSubmitVo.getUserId());
        huibidangan.setDate(huibidanganSubmitVo.getDate());
        huibidangan.setHuibiName(huibidanganSubmitVo.getHuibiName());
        huibidangan.setQingjing(huibidanganSubmitVo.getQingjing());
        huibidangan.setGanshou(huibidanganSubmitVo.getGanshou());
        huibidangan.setChangshi(huibidanganSubmitVo.getChangshi());
        huibidangan.setYingxiang(huibidanganSubmitVo.getYingxiang());
        huibidangan.setZenme(huibidanganSubmitVo.getZenme());
        huibidangan.setRecordId(-1);

        int res = huibidanganMapper.insert(huibidangan);
        if (res > 0) {
            return ResponseBean.success();
        }
        return ResponseBean.error(ResponseBeanEnum.ERROR);
    }
}

